import type { ExecutionContext } from '@nestjs/common';
import { createParamDecorator } from '@nestjs/common';

const GetUserIp = createParamDecorator((data, ctx: ExecutionContext) => {
  const request = ctx.switchToHttp().getRequest();
  return request.ip.match(/\d+\.\d+\.\d+\.\d+/)?.join('.');
});

const GetUserAgent = createParamDecorator((data, ctx: ExecutionContext) => {
  const request = ctx.switchToHttp().getRequest();
  return request.headers['user-agent'];
});

export { GetUserIp, GetUserAgent };
